#!/bin/bash

# Test that wp-get-dumps script works. To do so, we download dumps for one of
# the smallest Wikipedias, Afar (http://aa.wikipedia.org).
#
# While the wiki is "closed" as of 4/23/2013, the content of the dump does
# change from time to time as the export format is updated.
#
# Copyright (c) Los Alamos National Security, LLC, and others.

. ./environment.sh

# Use a generic location rather than test-specific so that we can configure
# the path.
cd $TMPDIR
rm -Rf wp-dumps
mkdir wp-dumps

# Do the mirror. The head pipe is to remove the statistics, which change.
y "wp-get-dumps 2>&1 | head -n 11"

# Dumps contain timestamps and system version information which change.
# Therefore, we need to extract the .gz files and do a little magic for a
# proper comparison.
x cd wp-dumps/aawiki/latest
y "zcat aawiki-latest-pagelinks.sql.gz | egrep -v '^--' > aawiki-latest-pagelinks.sql"
y "zcat aawiki-latest-stub-meta-history.xml.gz | fgrep -v '<generator>' > aawiki-latest-stub-meta-history.xml"
x head -5 aawiki-latest-pagelinks.sql
x tail -5 aawiki-latest-pagelinks.sql
x head -5 aawiki-latest-stub-meta-history.xml
x tail -3 aawiki-latest-stub-meta-history.xml
